/**
 * 斐波那契数
 * https://leetcode-cn.com/problems/fibonacci-number/
 * @author yinye
 * @since 2020-02-01 16:23
 */
public class FibonacciNumber {
    public int fib(int N) {
        if(N < 2){
            return N;
        }
        int first = 0;
        int second = 1;
        /*
         * 0    1	2	3	4	5	6
         * 0	1	1	2	3	5	8
         * 第n个斐波那契数等于前2个数相加 n-1 次
         */
        for (int i = 1; i < N; i++) {
            second = first + second;
            first = second - first;
        }
        return second;
    }

    public static void main(String[] args) {
        int n = 10;
        for (int i = 0; i < n; i++) {
            System.out.println("第" + i + "个斐波那契数 = " + new FibonacciNumber().fib(i));
        }
    }
}
